#include <iostream>
#include <cstring>
using namespace std;

#define MAC_ADDRESS_LENGTH 6//定义MAC地址长度

typedef unsigned char MAC_address[MAC_ADDRESS_LENGTH];//定义MAC地址类型

//定义以太网帧结构体
struct EthernetFrame
{
    MAC_address destination_address; //目的地址
    MAC_address source_address;      //源地址
    unsigned short ether_type;        //以太网类型
    unsigned char payload[1500];      //数据负载
    unsigned int crc;                 //CRC校验码
};

MAC_address this_mac_address={0x00,0x1A,0x2B,0x3C,0x4D,0x5E};//定义本机MAC地址

// 判断目的地址是否匹配本机地址、多播地址或广播地址
int mac_address_match(const struct EthernetFrame *frame)
{
    static const MAC_address broadcast_address={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};// 广播地址：全1的MAC地址
    if(memcmp(frame->destination_address,broadcast_address,MAC_ADDRESS_LENGTH)==0) return 1;//检查是否是广播地址
    if((frame->destination_address[0]&0x01)==0x01) return 1;//检查是否是多播地址（多播地址的第一字节的最低有效位为1）
    if(memcmp(frame->destination_address,this_mac_address,MAC_ADDRESS_LENGTH)==0) return 1;//检查是否与本机地址匹配
    return 0;//如果不匹配任何条件，返回0
}

int main()
{
    EthernetFrame frame;//创建一个以太网帧
    MAC_address broadcast_address={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};//设置目的地址为广播地址
    memcpy(frame.destination_address, broadcast_address, MAC_ADDRESS_LENGTH);
    //检查是否匹配
    if(mac_address_match(&frame)) std::cout << "Frame matches broadcast address." << std::endl;
	else std::cout << "Frame does not match any address." << std::endl;
    return 0;
}